#include "container.hpp"
#include <cassert>
#include <stdexcept>
#include <iostream>

// Test boundary conditions
void test_boundary_conditions() {
    Mesh mesh(5, 5);
    mesh.setBoundaryCondition(0, 0, 1.0);
    
    assert(mesh.getValue(0, 0) == 1.0);
    std::cout << "Boundary condition test passed" << std::endl;
}

// Test out of range error
Mesh test_out_of_range() {
    Mesh mesh(5, 5);
    try {
        mesh.getValue(10, 10); // Out of bounds
        assert(false && "Should have thrown out_of_range");
    } catch (const std::out_of_range&) {
        std::cout << "Out of range test passed" << std::endl;
    }

	return mesh;
}

// Test stencil operations
void test_stencil_operations(Mesh mesh) {
    // Set boundary conditions on all edges
    for (int i = 0; i <= 5; ++i) {
        mesh.setBoundaryCondition(i, 0, 1.0);   // Top edge
        mesh.setBoundaryCondition(i, 5, -1.0);  // Bottom edge
        mesh.setBoundaryCondition(0, i, 0.5);   // Left edge
        mesh.setBoundaryCondition(5, i, -0.5);  // Right edge
    }
    
    mesh.solvePoisson();
    
    // The solution should be non-zero at interior points
    double value = mesh.getValue(2, 2);
    assert(value != 0.0);
    std::cout << "Stencil operation test passed (value at (2,2): " << value << ")" << std::endl;
}

int main() {
    test_boundary_conditions();
    Mesh m = test_out_of_range();
    test_stencil_operations(m);
    
    std::cout << "All tests passed!" << std::endl;
    return 0;
}
